<?php
/**
 * Created by PhpStorm.
 * User: xuewl
 * Date: 2018/1/5
 * Time: 14:44
 */

namespace app\notification\behavior;


class ProductOrderTransfer
{
    public function run(&$params){}

    /**
     * 客户转接
     * @param $params
     */
    public function CreateAfter(&$params) {
        \think\Lang::load(APP_PATH . 'notification/lang/zh-cn.php');
        $lang = \think\Lang::get('notification');
        $notification = $lang['客户转移请求'];

        $replace = [
            '{{转出客户经理}}' => (string) $params->order_info->customer_info->customer_realname,
        ];

        if ($notification['sms'] && $params->order_info->customer_info->mobile) {
            $mobile = $params->order_info->customer_info->mobile;
            $template_id = $notification['sms']['template_id'];
            $template_vars = str_replace(array_keys($replace), $replace, $notification['sms']['template_vars']);
            model('admin/dysms', 'service')->send($mobile, $template_vars, $template_id);
        }

        if($notification['message']) {
            $title = $notification['message']['title'];
            $content = str_replace(array_keys($replace), $replace, $notification['message']['content']);
            model('message/message', 'service')
                ->send($params->touid, $title, $content, $params->formuid, [
                    'role' => 2,
                    'order_sn' => $params->order_sn,
                    'target' => '/pages/customer/product_order/receive?sn='.$params->order_sn
                ]);
        }
    }

}
